<?php

namespace app\common\model\finance;

use app\common\model\BaseModel;

class TransactionRecord extends BaseModel
{
    
    protected $name = 'transaction_record';

    public function searchCreateTimeStartAttr($query, $value, $data)
    {
        if ($value) {
            $query->where('transaction_date', '>=', $value);
        }
    }



    public function searchCreateTimeEndAttr($query, $value, $data)
    {
        if ($value) {
            $query->where('transaction_date', '<=', $value.' 23:59:59');
        }
    }

    public function searchGroupByAttr($query, $value, $data)
    {
        if ($value == 'daily') {
            $query->group('DATE(transaction_date), user_id');
        }else{
            $query->group('user_id');
        }
    }

    public function searchMonthAttr($query, $value, $data)
    {
        $query->where('DATE_FORMAT(transaction_date, "%Y-%m")','=',$value);

    }
    
}